package com.heima.wemedia.controller.v1;

import com.heima.model.common.dtos.PageRequestDto;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.model.wemedia.dtos.WmNewsDto;
import com.heima.model.wemedia.dtos.WmNewsPageReqDto;
import com.heima.model.wemedia.pojos.WmNews;
import com.heima.wemedia.service.WmNewsService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/api/v1/news")
public class WmNewsController {

    @Autowired
    public WmNewsService wmNewsService;

    @PostMapping("/list")
    public ResponseResult findAll(@RequestBody WmNewsPageReqDto wmNewsPageReqDto) {
        return wmNewsService.findAll(wmNewsPageReqDto);
    }


    @GetMapping("/del_news/{id}")
    public ResponseResult del_news(@PathVariable Integer id) {
        wmNewsService.removeById(id);
        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }

    @GetMapping("/one/{id}")
    public ResponseResult one(@PathVariable Integer id) {
        log.info("=======================");
        WmNews wmNews = wmNewsService.getById(id);
        return ResponseResult.okResult(wmNews);
    }
    @PostMapping("/submit")
    public ResponseResult submitNews(@RequestBody WmNewsDto wmNewsDto) {
        return wmNewsService.submitNews(wmNewsDto);
    }

    @PostMapping("/down_or_up")
    public ResponseResult downOrUp(@RequestBody WmNewsDto dto) {
        return wmNewsService.downOrUp(dto);
    }

    @PostMapping("/list_vo")
    public ResponseResult list_vo(@RequestBody PageRequestDto dto) {
        return wmNewsService.list_vo(dto);
    }

    @GetMapping("/one_vo/{id}")
    public ResponseResult one_vo(@PathVariable Integer id) {
        return wmNewsService.one_vo(id);
    }

    @PostMapping("/auth_fail")
    public ResponseResult auth_fail(@RequestBody Map<String,String> map) {
        return wmNewsService.auth_fail(map);
    }

    @PostMapping("/auth_pass")
    public ResponseResult auth_pass(@RequestBody Map<String,String> map) {
        return wmNewsService.auth_pass(map);
    }
}
